package com.conv.shop.business.controller;

import com.conv.shop.business.domain.AdminInfo;
import com.conv.shop.business.service.AdminService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/admin")
public class AdminManageController {
    @Resource

   private AdminService adminService;
    @GetMapping("/hello")
    public String hello(){
        return "Admin,Hello SpringBoot";
    }

    /**
     * 管理员登录
     * @param adminInfo
     * @param request
     * @return String
     */
    @GetMapping("/login")
    public String adminLogin(AdminInfo adminInfo, HttpServletRequest request){
        if (adminService.adminLogin(adminInfo)){
            request.getSession().setAttribute("adminInfo", adminInfo);
            return "index";
        }else{
            request.getSession().setAttribute("msg", "账号或者密码错误");
            return "login";
        }
    }
}
